﻿Imports System.IO
Imports System.IO.IsolatedStorage

Public Class IsolatedContentManager
    Inherits Microsoft.Xna.Framework.Content.ContentManager

    Public Property IsolatedStorageRootDirectory() As String

#If WINDOWS_PHONE Then
    Private m_fileStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
#ElseIf WINDOWS Then
    Private m_fileStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
#End If

    Public Sub New(serviceProvider As System.IServiceProvider, Optional ByVal fs As IsolatedStorageFile = Nothing)
        MyBase.New(serviceProvider)
        Me.m_fileStorage = If(fs, Me.m_fileStorage)
    End Sub

    Public Sub New(serviceProvider As System.IServiceProvider, rootDirectory As String, Optional ByVal fs As IsolatedStorageFile = Nothing)
        MyBase.New(serviceProvider, rootDirectory)
        Me.IsolatedStorageRootDirectory = rootDirectory
        Me.m_fileStorage = If(fs, Me.m_fileStorage)
    End Sub

    Public Function LoadSpriteFont(assetName As String) As SpriteFont
        Return MyBase.Load(Of SpriteFont)(assetName)
    End Function

    Protected Overrides Function OpenStream(assetName As String) As System.IO.Stream
        Return Me.m_fileStorage.OpenFile(IO.Path.Combine(Me.IsolatedStorageRootDirectory, assetName), FileMode.Open)
    End Function

End Class